#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/1/16 14:05
# @Author : 闫峰
# @File    : jdw.jdw.channels.walmart.product.getListingProduct.py
import json
from common.setting import ensure_path_sep

import requests

from third_services.jdw.ept.api import get_result_bei

session = requests.session()


class Jdw:

    def __init__(self, ordersourceid):
        self.ordersourceid = ordersourceid

    def jd_jdw_channels_walmart_product_getListingProduct(self, skuList):
        """根据商家 ID 分页查询商品 listing 列表"""
        appUserPin = self.jd_jdw_channels_walmart_product_queryChannel()['model'][0]['userPin']
        method = "jd.jdw.channels.walmart.product.getListingProduct"
        param = {"request": {"appUserPin": appUserPin, "skuList": skuList}}
        param_json = json.dumps(param)
        # print(self.get_result_bei(self.ordersourceid, method, param_json))
        return get_result_bei(self.ordersourceid, method, param_json)

    def jd_jdw_channels_walmart_product_getReturnAddress(self):
        """根据商家 ID 和店铺信息获取退货地址信息"""

        method = "jd.jdw.channels.walmart.product.getReturnAddress"
        param = {
        	    "appUserPin":"ept_JRvALYZltjTn"
        }
        param_json = json.dumps(param)

        return get_result_bei(self.ordersourceid, method, param_json)

    def jd_jdw_channels_walmart_product_queryCategories(self):
        """根据分类获取沃尔玛大类的信息"""
        method = "jd.jdw.channels.walmart.product.queryCategories"
        param = {
        	    "type":1
        }
        param_json = json.dumps(param)
        return get_result_bei(self.ordersourceid, method, param_json)

    def jd_jdw_channels_walmart_product_queryChannel(self):
        """根据商家 ID 获取用户授权的店铺信息"""

        method = "jd.jdw.channels.walmart.product.queryChannel"
        param = {}
        param_json = json.dumps(param)
        # print(get_result_bei(self.ordersourceid, method, param))
        return get_result_bei(self.ordersourceid, method, param_json)

    def jd_jdw_channels_walmart_product_queryFailProduct(self):
        """根据商家 ID 分页查询失败商品信息"""

        method = "jd.jdw.channels.walmart.product.queryFailProduct"
        param = {"request":{"appUserPin":"ept_5b2d080b9541a"}}
        param_json = json.dumps(param)
        return get_result_bei(self.ordersourceid, method, param_json)

    def jd_jdw_channels_walmart_product_queryFullProduct(self):
        """全量商品查询"""
        method = "jd.jdw.channels.walmart.product.queryFullProduct"
        param = {
        	"request": {
        	    "pageNo":1,
        	    "pageSize":10,
        	    "sku":"1053220406"
        	}   
        }

        param_json = json.dumps(param)
        return get_result_bei(self.ordersourceid, method, param_json)

    def jd_jdw_channels_walmart_product_queryJsonschema(self):
        """根据商品类型和 block 类型获取 json schema"""

        method = "jd.jdw.channels.walmart.product.queryJsonschema"
        param = {"block": "1", "type": "1"}
        param_json = json.dumps(param)
        return get_result_bei(self.ordersourceid, method, param_json)

    def jd_jdw_channels_walmart_product_queryProductItem(self):
        """查询商品详细信息"""
        appUserPin = self.jd_jdw_channels_walmart_product_queryChannel()['model'][0]['userPin']
        method = "jd.jdw.channels.walmart.product.queryProductItem"
        param = {"sku": "1071581922", "appUserPin": appUserPin}
        param_json = json.dumps(param)
        return get_result_bei(self.ordersourceid, method, param_json)

    def jd_jdw_channels_walmart_product_querySlaveProduct(self):
        """根据商家 ID 分页获取商品信息列表"""

        method = "jd.jdw.channels.walmart.product.querySlaveProduct"
        # param1 = '{"request":{"appUserPin":"ept_5b2d080b9541a","skuList":["1000759083"],"operType":1}}'
        param = {"request":
                     {"appUserPin": "ept_sOBhCOxacgHH",
                      "skuList": ["3676692"],
                      "operType": 3
                      }
                 }
        param_json = json.dumps(param)
        return get_result_bei(self.ordersourceid, method, param_json)

    def jd_jdw_channels_walmart_product_querysSchema(self):
        """根据大类和商品类型获取jsonschema"""

        method = "jd.jdw.channels.walmart.product.querysSchema"
        param = {"category": "Baby Diapering, Care, & Other", "type": "1"}
        # method2 = 'jdw.ept.seller.stock.getStock'
        # param = '{"skuIds":[968891967,719548584]}'
        param_json = json.dumps(param)
        return get_result_bei(self.ordersourceid, method, param_json)

    def jd_jdw_channels_walmart_product_querySubCategory(self):
        """获取沃尔玛子类目"""

        method = "jd.jdw.channels.walmart.product.querySubCategory"
        param = {
        	    "type":"1"
        }
        param_json = json.dumps(param)
        return get_result_bei(self.ordersourceid, method, param_json)


if __name__ == '__main__':
    # skuList= ['1055205031', '1055182977', '1055152796', '1055141514', '1055180543', '1055151929',
    #           '1055147778', '1055123923', '1055180002', '1055170043', '1055157913', '1055125803',
    #           '1055172493', '1055148215', '1055129555', '1055181902', '1055166469', '1055153370',
    #           '1055151341', '1055143153', '1055142748', '1055174167', '1055172641', '1055164463',
    #           '1055161927', '1055147617', '1055140938', '1055127237', '1055169477', '1055154585',
    #           '1055148752', '1055145666', '1055144027', '1055137475', '1055176553', '1055167424',
    #           '1055187644', '1055149644', '1055141201', '1055130128', '1055161766', '1055134085'
    #           ]
    t = Jdw(20395)
    res = t.jd_jdw_channels_walmart_product_queryChannel()
    print(res)
    print(json.dumps(res))
    # res = t.jd_jdw_channels_walmart_product_getListingProduct(["1000759072"])
    # print(res)
    # jsonData = jsonpath.jsonpath(res,"$..jsonData")[0]
    # print()
